package ru.infosystem.client;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author akoshi
 */

public class BDConnection {
    
    private Socket       socket   = null;
    
    private InputStream  in       =  null;
    
    private OutputStream out      = null;
    
    private ObjectOutputStream objOut = null;
    
    private ObjectInputStream objIn = null;
    
    
    public BDConnection(Socket socket, InputStream in, OutputStream out) {        
        try {
            this.in     = in;
            this.out    = out;
            this.objIn = new ObjectInputStream(this.in);
            this.objOut = new ObjectOutputStream(this.out);
            this.socket = socket;
        } catch (IOException ex) {
            Logger.getLogger(BDConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    
    
    public InputStream getInputStream() {
        return in;
    }
    
    public OutputStream getOutputStream() {
        return out;
    }
    
    public ObjectOutputStream getObjOutputStream(){
        return this.objOut;
    }
    
    public ObjectInputStream getObjInputStrem(){
        return this.objIn;
    }
        
    public void close() {

        try {
            
                socket.close();
                this.objIn.close();
                this.objOut.close();
                in.close();
                out.close();                
                
        } catch (IOException e) {
                System.out.println("Server error");
        }
    }
    
}
